<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.BufferLines</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_buffer_lines_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Spec - howl.BufferLines</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.bufferlines">howl.BufferLines</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="k">with</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;    </span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="#-operator-returns-number-of-lines-in-the-buffer"># operator returns number of lines in the buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello\n  world\nagain!'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="delete(start,-end)-deletes-the-the-lines-[start,-end]">delete(start, end) deletes the the lines [start, end]</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ\nwØrld\nagain!'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'again!'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="at_pos(pos)-returns-the-line-at-&lt;pos&gt;">at_pos(pos) returns the line at &lt;pos&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'Øne\ntwØ\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">at_pos</span><span class="w"> </span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'twØ'</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="supports-iterating-using-ipairs">supports iterating using ipairs</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\nthree'</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">ipairs</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="supports-iterating-using-pairs">supports iterating using pairs</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\nthree'</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="line-objects">Line objects</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hƏllØ\n  wØrld\nagain!'</span><span class="w">&#x000A;  </span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".buffer-points-to-the-corresponding-buffer">.buffer points to the corresponding buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">buffer</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".nr-holds-the-line-number">.nr holds the line number</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">nr</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".text-returns-the-text-of-the-specified-line,-sans-linebreak">.text returns the text of the specified line, sans linebreak</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'  wØrld'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'again!'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="tostring(line)-gives-the-same-as-.text">tostring(line) gives the same as .text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".indentation-returns-the-indentation-for-the-line">.indentation returns the indentation for the line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".indentation-=-&lt;nr&gt;-set-the-indentation-for-the-line-to-&lt;nr&gt;">.indentation = &lt;nr&gt; set the indentation for the line to &lt;nr&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllØ\n  wØrld\n    again!'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".start_pos-returns-the-start-position-for-line">.start_pos returns the start position for line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".end_pos-returns-the-end-position-for-line,-right-before-the-newline">.end_pos returns the end position for line, right before the newline</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".byte_start_pos-returns-the-byte-start-position-for-line">.byte_start_pos returns the byte start position for line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö\nwØrld'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">byte_start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".byte_end_pos-returns-the-byte-end-position-for-line">.byte_end_pos returns the byte end position for line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö\nwØrld'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_end_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_end_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".previous-returns-the-line-above-this-one,-or-nil-if-none">.previous returns the line above this one, or nil if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">previous</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">previous</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".previous_non_blank-returns-the-first-preceding-non-blank-line,-or-nil-if-none">.previous_non_blank returns the first preceding non-blank line, or nil if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">previous_non_blank</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">previous_non_blank</span><span class="w">&#x000A;</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">].</span><span class="n">previous_non_blank</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".next_non_blank-returns-the-first-succeding-non-blank-line,-or-nil-if-none">.next_non_blank returns the first succeding non-blank line, or nil if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">next_non_blank</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">next_non_blank</span><span class="w">&#x000A;</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">next_non_blank</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".next-returns-the-line-below-this-one,-or-nil-if-none">.next returns the line below this one, or nil if none</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nb">next</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="nb">next</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".indent()-indents-the-line-by-&lt;config.indent&gt;">.indent() indents the line by &lt;config.indent&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">indent</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllØ\n  wØrld\nagain!'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">\</span><span class="n">indent</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllØ\n  wØrld\n again!'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".unindent()-unindents-the-line-by-&lt;config.indent&gt;">.unindent() unindents the line by &lt;config.indent&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  first\n  second'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\n  second'</span><span class="w">&#x000A;&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\n second'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="#line-returns-the-length-of-the-line">#line returns the length of the line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="mi">5</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="lines-are-equal-if-they-have-the-same-text">lines are equal if they have the same text</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="string-methods-can-be-accessed-directly-on-the-object">string methods can be accessed directly on the object</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'first line'</span><span class="w">&#x000A;</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'fi'</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">line</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'in'</span><span class="p">))</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'first win'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">line</span><span class="o">\</span><span class="n">gsub</span><span class="p">(</span><span class="s1">'line'</span><span class="p">,</span><span class="w"> </span><span class="s1">'win'</span><span class="p">))</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="string-properties-can-be-accessed-directly-on-the-object">string properties can be accessed directly on the object</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_empty</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_blank</span><span class="w">&#x000A;</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_empty</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_blank</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".text-=-&lt;content&gt;">.text = &lt;content&gt;</h3>&#x000A;&#x000A;<h4 id="replaces-the-line-text-with-&lt;content&gt;">replaces the line text with &lt;content&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Hola'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'Hola\n  wØrld\nagain!'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-&lt;content&gt;-is-nil">raises an error if &lt;content&gt; is nil</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'nil'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=".chunk">.chunk</h3>&#x000A;&#x000A;<h4 id="a-chunk-object-for-the-line,-disregarding-the-newline">a Chunk object for the line, disregarding the newline</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllØ\nbare'</span><span class="w">&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Chunk'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w"> </span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span><span class="w">&#x000A;&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'bare'</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="is-an-empty-chunk-for-empty-lines">is an empty chunk for empty lines</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\n'</span><span class="w">&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span><span class="w">&#x000A;&#x000A;</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">chunk</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="[nr]">[nr]</h2>&#x000A;&#x000A;<h4 id="returns-a-line-object-for-the-specified-line">returns a line object for the specified line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello\n  world\nagain!'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-nil-if-the-line-number-is-invalid">returns nil if the line number is invalid</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello!'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="[nr]-=-&lt;value&gt;">[nr] = &lt;value&gt;</h2>&#x000A;&#x000A;<h4 id="replaces-the-text-of-the-specified-line-with-&lt;value&gt;">replaces the text of the specified line with &lt;value&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ\nwØrld'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hØla'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hØla\nwØrld'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="removes-the-entire-line-if-value-is-nil">removes the entire line if value is nil</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'gØØdbye\ncruel\nwØrld'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'gØØdbye\nwØrld'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'wØrld'</span><span class="w"> </span><span class="p">,</span><span class="n">b</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-the-line-number-is-invalid">raises an error if the line number is invalid</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello!'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid index'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="s1">'foo'</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bar'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="range">range<span class="arg-list">(start, end)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-table-with-lines-[start,-end]">returns a table with lines [start, end]</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">range</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="start-can-be-greater-than-end">start can be greater than end</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">range</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="for_text_range">for_text_range<span class="arg-list">(start_pos, end_pos)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-table-with-lines-between-[start_pos,-end_pos]">returns a table with lines between [start_pos, end_pos]</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="start_pos-can-be-greater-than-end_pos">start_pos can be greater than end_pos</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-include-lines-only-touched-at-the-start-or-end-positions">does not include lines only touched at the start or end positions</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">start_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="append">append<span class="arg-list">(text)</span></h2>&#x000A;&#x000A;<h4 id="append(text)-appends-&lt;text&gt;-with-the-necessary-newlines">append(text) appends &lt;text&gt; with the necessary newlines</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'three'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo\nthree\n'</span><span class="w">&#x000A;&#x000A;</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\n'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'three'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo\nthree\n'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-a-line-object-for-the-newly-appended-line">returns a line object for the newly appended line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'line'</span><span class="w">&#x000A;</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'omega'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="insert">insert<span class="arg-list">(line_nr, text)</span></h2>&#x000A;&#x000A;<h4 id="inserts-a-new-line-at-&lt;nr&gt;-with-&lt;text&gt;">inserts a new line at &lt;nr&gt; with &lt;text&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'half'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'half\none\ntwo'</span><span class="w">&#x000A;&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'1.5'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'half\none\n1.5\ntwo'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="appends-the-line-if-line_nr-is-just-beyond-the-last-line">appends the line if line_nr is just beyond the last line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\nsecond'</span><span class="w">&#x000A;</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\nsecond\nfoo\n'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-&lt;line_nr&gt;-is-invalid">raises an error if &lt;line_nr&gt; is invalid</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\nsecond'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-a-line-object-for-the-newly-inserted-line">returns a line object for the newly inserted line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'line'</span><span class="w">&#x000A;</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'alpha'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
